package com.mySampleApplication.client.codeRule;


import com.google.gwt.user.client.rpc.AsyncCallback;
import com.mySampleApplication.client.CodeRuleAtter.CodeRuleAtter;
import com.mySampleApplication.client.CodeRuleAtter.CodeRuleAtterDto;
import com.mySampleApplication.client.CodeRuleAtter.CodeRuleAtterService;
import com.mySampleApplication.client.components.SDataSource;
import com.mySampleApplication.client.dmp.DmpDto;
import com.mySampleApplication.client.dmp.DmpService;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.data.fields.DataSourceBooleanField;
import com.smartgwt.client.data.fields.DataSourceDateField;
import com.smartgwt.client.data.fields.DataSourceEnumField;
import com.smartgwt.client.data.fields.DataSourceFloatField;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.form.validator.FloatPrecisionValidator;
import com.smartgwt.client.widgets.form.validator.FloatRangeValidator;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ItemSupplyXmlDS  extends VLayout {

    public  ItemSupplyXmlDS(Window winModal) {
        {
            // 创建一个垂直布局容器
            VLayout layout = new VLayout(10); // 参数15为布局成员之间的间距
            layout.setWidth100();
            layout.setHeight100();
//            layout.setPadding(10);
//            DataSource dataSource = SDataSource.getDataSource();
            Map<String, Object> listMap =dataObjecForm.getListGrid(null,null,winModal,null,null);
            ListGrid listGrid = (ListGrid) listMap.get("listGrid");
            List<ListGridRecord> recordList = new ArrayList<>();
            Map<String, String> mapPage = new HashMap<>();
            mapPage.put("pageSize", "1");
            mapPage.put("pageNumber", "10");
            Map<String, String> mapf = new HashMap<>();
//            if (frecord != null) {
//                mapf.put("coderule_id", frecord.getAttribute("id"));
                DmpService.App.getInstance().selectObjectList(new AsyncCallback<DmpDto>() {
                    public void onSuccess(DmpDto dmpDto) {
                        List<Map<String, String>> keyValueMap = dmpDto.getKeyValueListMap();
                        for (Map<String, String> data : keyValueMap) {
                            ListGridRecord record = new ListGridRecord();
                            data.forEach((k, v) -> {
                                record.setAttribute(k, v);
                            });
                            // 设置其他需要的属性
                            recordList.add(record);
                        }
                        listGrid.setData(recordList.toArray(new ListGridRecord[0]));
                        //SC.say( "获取数据成功！"+modelId);
                        //list.addAll(result);
                    }

                    public void onFailure(Throwable caught) {
                        SC.warn("获取数据失败！");
                    }
                });
//            }


            // 设置数据源到列表网格
//             listGrid.setDataSource(dataSource);
            // 加载数据
            listGrid.fetchData();
            // 添加列表网格到布局容器中
            layout.addMember(listGrid);
            layout.addMember((HLayout) listMap.get("buttonLayout"));


            // 添加布局容器到页面中
            this.addChild(layout);
        }

    }
}
